package chapter4;
import java.util.Scanner;
/****************************************************************
 * Author：icynlau
 * Description:  十六进制转二进制
 * 			注意，这里我偷懒，没用十进制数与二进行不断取余的转换运算，而是直接使用一个字符串数组完成对换
 * Date:2021/4/2
 * ***************************************************************
 */
public class exc4_12 {
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		System.out.print("Enter a hex digit:");
		String s=input.next();
		char ch=s.charAt(0);
		String[] sArray= {"0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"};
		
		int n=0;
		if(ch>='0'&&ch<='9') {
			n=ch-'0';
		}else if(ch>='A'&&ch<='F'){
			n=ch-'A'+10;
		}else {
			System.out.printf("%c is a invalid input.", ch);
			System.exit(1);
		}
		System.out.printf("The binary value is %s", sArray[n]);
		
	}

}
